package company.dj_F;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class DaJ3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int row = Integer.parseInt(sc.nextLine());
        char[][] dict = new char[row][];
        //int[][] used = new int[row][];
        List<List<Integer>> used = new ArrayList<>();
        for (int i = 0; i < row; i++) {
            String s = sc.nextLine();
            dict[i] = s.toCharArray();
            List<Integer> list = new ArrayList<>();
            for (int j = 0; j < s.length(); j++) {
                list.add(0);
            }
            used.add(list);
        }
        int n = Integer.parseInt(sc.nextLine());
        String[] strings = new String[n];
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            strings[i] = sc.nextLine();
            for (int j = 0; j < dict.length; j++) {
                for (int k = 0; k < dict[j].length; k++) {
                    helper(i, strings[i], 0, j, k, dict, used, ans);
                    clearList(used);
                }
            }
        }
//        helper(0, strings[0], 0, 3, 3, dict, used, ans);
        for (int i = 0; i < n; i++) {
            if (ans[i] == 1)
                System.out.println(strings[i]);
        }
    }

    private static void clearList(List<List<Integer>> used) {
        for (int i = 0; i < used.size(); i++) {
            List<Integer> list = used.get(i);
            for (int j = 0; j < list.size(); j++) {
                list.set(j, 0);
            }
        }
    }

    private static void helper(int index, String s, int step, int x, int y, char[][] dict, List<List<Integer>> used, int[] ans) {
        //下标不正确
//        System.out.println(x + " " + y);
        // 忘记判断used
        if (x < 0 || x >= dict.length || y < 0 || y >= dict[x].length || used.get(x).get(y) == 1)
            return;
        // 已经能正确识别了
        if (ans[index] == 1)
            return;
//        System.out.println(used);
        char c = s.charAt(step);
        if (c == dict[x][y]) {
            if (step == s.length() - 1) {
                ans[index] = 1;
            } else {
                used.get(x).set(y, 1);
                helper(index, s, step + 1, x + 1, y, dict, used, ans);
                helper(index, s, step + 1, x - 1, y, dict, used, ans);
                helper(index, s, step + 1, x, y + 1, dict, used, ans);
                helper(index, s, step + 1, x, y - 1, dict, used, ans);
                used.get(x).set(y, 0);
            }
        }
    }
}
